<?php

	class Helper{
		
		
		public static function send_mail($to,$subject,$body){
		
			$sql = "EXEC sp_send_email 'customercare@loginvn.com',:EMAIL_TO,:SUBJECT,:BODY";
			$command = Yii::app()->db->createCommand($sql);
			$command->bindParam(':EMAIL_TO',$to,PDO::PARAM_STR);
			$command->bindParam(':SUBJECT',$subject,PDO::PARAM_STR);
			$command->bindParam(':BODY',$body,PDO::PARAM_STR);
			$command->execute();			
			
		}
		
		public static function compare_lastname($a, $b) { 
			return strnatcmp($a['name'], $b['name']); 
			
		} 
		
		public static function generation_random_number($number){
			
			$characters = array("1","2","3","4","5","6","7","8","9","0");
			$keys = array();
			while(count($keys) < 9) {
			    $x = mt_rand(0, count($characters)-1);
			    if(!in_array($x, $keys)) {
			       $keys[] = $x;
			    }
			}
			$random_chars= null;
			foreach($keys as $key){
			   $random_chars .= $characters[$key];
			}
			return $random_chars;
		}
		
		public static function send_mail_message($from,$to,$subject,$message){
		
			$headers = 'From:'.$from."\r\n" .
			           'Reply-To:'.$from."\r\n" ;
			$headers.= 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=UTF-8' . "\r\n";   
		
			mail($to, $subject, $message, $headers);	
			
		}

		public static function formatPhoneNumber($phone_number){
			return substr($phone_number,0,3)."-".substr($phone_number,3,3)."-".substr($phone_number,6,4);
		}		
		
		
		public static function param($name, $default = null)
		{
		    if ( isset(Yii::app()->params[$name]) )
		        return Yii::app()->params[$name];
		    else
		        return $default;
		}
		
		public static function show_notification($object,$menu_id){
			$object->render('notification',array(
				'menu_id' => $menu_id
			));	
		}
	}